<?php

class Shop_Branchs extends Eloquent {
    protected $table = 'shop_branchs';
    

    public static function  Insert($name,$shop_id,$warehourse_id,$address,$phone){
        try{
            $shop_branchs= new Shop_Branchs();
                $shop_branchs->name = $name;
                $shop_branchs->shop_id =$shop_id;
                $shop_branchs->warehourse_id=$warehourse_id;
                $shop_branchs->address=$address;
                $shop_branchs->phone =$phone;
                $shop_branchs->save();
                $shop_branchs_id = $shop_branchs->id;
                return $shop_branchs_id;
        }
        catch(Exception $e)
        {
            throw $e;
        }
        
    }

    public static function Edit($name,$warehourse_id,$address,$phone,$branch_id)
    {
        try{
            $query_update="UPDATE shop_branchs 
                                    SET updated_at=CURRENT_TIMESTAMP,
                                        name ='$name',
                                        warehourse_id='$warehourse_id',
                                        address='$address',
                                        phone='$phone'
                                        
                                     WHERE id='$branch_id'";
             //echo $query_update;
            DB::update($query_update);
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    
     public static function Del($branch_id)
    {
        try{
          
            DB::table('shop_branchs')->where('id','=',$branch_id)->delete();
            return true;
        }
        catch(Exception $e)
        {
            throw $e;
        }
    }
    
    
    public static function ListBranch($shop_id)
    {        
          try{
            
          $query_select="SELECT *  FROM shop_branchs WHERE shop_id = $shop_id ";
            return DB::select(DB::raw($query_select));
                        
          
        }
        catch(Exception $e)
        {
            throw $e;
        }
        
    }
    
    
}

?>
